package com.googlecode.agscrum.model.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Version;

import org.hibernate.annotations.Cascade;

@Entity
@SequenceGenerator(name = "resource_sequence", sequenceName = "resource_sequence")
@Table(name = "RESOURCES")
public class Resource {
	@Id
	@GeneratedValue(generator = "resource_sequence", strategy = GenerationType.SEQUENCE)
	@Column(name = "id_resource")
	private Long id;

	@Column(unique = true, nullable = false)
	private String name;
	@Version
	private Integer version;
	@Column(length = 70, nullable = false)
	private String description;
	@Column(nullable = true, length = 200)
	private String path;

	@ManyToOne
	@JoinColumn(name = "ID_RESOURCE_PARENT", referencedColumnName = "ID_RESOURCE", nullable = true)
	private Resource resourceParent;

	@OneToMany(mappedBy = "resource", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@Cascade(value = { org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
	@JoinColumn(name = "ID_RESOURCE")
	private List<Action> actions;

}
